<?php
if(!session_id()) { session_start(); }
if(!isset($_SESSION['user_type'])) {
	header('Location: index.php');
}
include_once('functions/main_functions.php');
	page_head();
?>
	<div id="main">
	<h2>User Manager</h2>
	<p>Userlist</p>
	<?php
	include_once('classes/user.class.php');
	$users = new User();
	$results = $users->selectAll();
	if($results != 0) {
		echo '
		<table>
			<tr>
				<th>
					User ID
				</th>
				<th>
					Username
				</th>
				<th>
					Action
				</th>
			</tr>
		';
		for($i = 0; $i < count($results); $i++) {
			$user_id = $results[$i]['user_id'];
			echo "
			<tr id='$user_id'>";
			echo '
				<td>
				';
				echo $results[$i]['user_id'];
			echo '
				</td>
				<td>
			';
				echo $results[$i]['username'];
			echo "
				</td>
				<td>
					<a id='admin-delete-user-button' onclick='delete_user($user_id); return false;'>Delete</a>
				</td>
			</tr>
			";
		}
		echo '</table>';
	} else {
		echo "No users found";
	}
	?>
	</div>
	<script src="js/main.js"></script>
	<?php
	page_foot();
?>